package com.erp.module.jingXiHua

import android.content.Context
import android.util.Log
import com.erp.Interface.OnUserDataInterface
import com.erp.bean.FileBean
import com.erp.bean.JingXiHuaBean
import com.erp.bean.JingXiHuaSouSuoBean
import com.erp.bean.PhotoBean
import com.erp.contacts.Contacts
import com.erp.contacts.Contacts.BOUNDARY
import com.erp.util.Httputil
import com.erp.util.Httputil.addtoken
import com.erp.util.Httputil.getparams
import com.erp.util.Myutil
import org.xutils.http.RequestParams
import org.xutils.x
import java.io.File

/**
 * Created by Administrator on 2019/4/13/013.
 * 作者：刘洋
 */
class JingXiHuaModel {
    /**获取卡诺亚资料列表 */
    fun JingXiHua(context: Context, page: Int, pagesize: Int, acbean : JingXiHuaSouSuoBean, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.ELABORATE_MANAGEMENT)
        Httputil.getparams(context, params)
        Httputil.setProsess(params)
        params.addBodyParameter("page", page.toString())
        params.addBodyParameter("pagesize", pagesize.toString())
        params.addBodyParameter("searchParams[duty_name]", acbean.duty_name)
        params.addBodyParameter("searchParams[guidance_name]", acbean.guidance_name)
        params.addBodyParameter("searchParams[file_category]", acbean.file_category)
        params.addBodyParameter("searchParams[approval_status]", acbean.approval_status)
        params.addBodyParameter("searchParams[time_filter][time_category]", acbean.time_category)
        if (acbean.start_time != "") {
            params.addBodyParameter("searchParams[time_filter][start_time]", Myutil.dateToStamp(acbean.start_time))
        }
        if (acbean.end_time != "") {
            params.addBodyParameter("searchParams[time_filter][end_time]", Myutil.dateToStamp(acbean.end_time))
        }
        x.http().get<String>(params, Httputil.Call(context, onUserDataInterface))
    }

    /**获取工号别表 */
    fun getZhiLiangGongHaoLieBiao(context: Context, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.ZHILIAN_GONGHAO)
        Log.d("TAAAG", "params=$params")
        Httputil.getparams(context, params)
        x.http().get<String>(params, Httputil.Call(context, onUserDataInterface))
    }
    /**修改保存精细化*/
    fun postJingXiHua(context: Context, bean : JingXiHuaBean, deletephoto : MutableList<PhotoBean>,deletefile : MutableList<FileBean>, onUserDataInterface: OnUserDataInterface){
        val params = RequestParams(Contacts.ELABORATE_MANAGEMENT+"/"+bean.id+"/edit")
        getparams(context, params)
        addtoken(params)
        Httputil.setProsess(params)
        params.addHeader("ACCEPT", "application/json")
        params.addBodyParameter("audit_status", bean.audit_status, BOUNDARY)
        params.addBodyParameter("approval_gonghao", bean.approval_gonghao, BOUNDARY)
        params.addBodyParameter("audit_defeated_reason", bean.audit_defeated_reason, BOUNDARY)
        params.addBodyParameter("approval_status", bean.approval_status, BOUNDARY)
        params.addBodyParameter("approval_defeated_reason", bean.approval_defeated_reason, BOUNDARY)
        params.addBodyParameter("content_scheme", bean.content_scheme, BOUNDARY)
        params.addBodyParameter("duty_department", bean.duty_department, BOUNDARY)
        params.addBodyParameter("duty_name", bean.duty_name, BOUNDARY)
        params.addBodyParameter("guidance_name", bean.guidance_name, BOUNDARY)
        params.addBodyParameter("file_category", bean.file_category, BOUNDARY)
        params.addBodyParameter("approval_gonghao", bean.approval_gonghao, BOUNDARY)
        params.addBodyParameter("audit_gonghao", bean.audit_gonghao, BOUNDARY)
        var addi = 0
        for(b in bean.listphoto){
            if(b.fid==""){
                params.addBodyParameter("files[new][$addi]", File(b.uri), BOUNDARY)
                addi++
            }
        }
        for(b in bean.listfile){
            if(b.fid==""){
                params.addBodyParameter("files[new][$addi]", File(b.uri), BOUNDARY)
                addi++
            }
        }
        var deletei = 0
        for (b in deletephoto) {
            if (b.fid != "") {
                params.addBodyParameter("files[delete][" + b.fid + "]", b.fid, BOUNDARY)
            }
        }
        x.http().post<String>(params, Httputil.Call(context, onUserDataInterface))
    }
}